//
//  XFSystem.m
//  WorkManager
//
//  Created by ukongm on 17/2/12.
//  Copyright © 2017年 ukongm. All rights reserved.
//
#import "XFSystem.h"
#import <sys/utsname.h>
@implementation XFSystem

+ (void)callPhone:(NSString *)phoneStr{
    NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",phoneStr];
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

+ (void)sendMailForPhone:(NSString *)phoneStr target:(UIViewController<MFMessageComposeViewControllerDelegate>*)target{
    MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
    controller.recipients = @[phoneStr];
    controller.messageComposeDelegate = target;
    [target presentViewController:controller animated:YES completion:nil];
}


+ (XFSystemDeviceType)getDeviceType{
    
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    if ([platform isEqualToString:@"iPhone4,1"]) return XFSystemDeviceType4S;
    if ([platform isEqualToString:@"iPhone5,1"]) return XFSystemDeviceType5;
    if ([platform isEqualToString:@"iPhone5,2"]) return XFSystemDeviceType5;
    if ([platform isEqualToString:@"iPhone5,3"]) return XFSystemDeviceType5C;
    if ([platform isEqualToString:@"iPhone5,4"]) return XFSystemDeviceType5C;
    if ([platform isEqualToString:@"iPhone6,1"]) return XFSystemDeviceType5S;
    if ([platform isEqualToString:@"iPhone6,2"]) return XFSystemDeviceType5S;
    if ([platform isEqualToString:@"iPhone7,1"]) return XFSystemDeviceType6Plus;
    if ([platform isEqualToString:@"iPhone7,2"]) return XFSystemDeviceType6;
    if ([platform isEqualToString:@"iPhone8,1"]) return XFSystemDeviceType6S;
    if ([platform isEqualToString:@"iPhone8,2"]) return XFSystemDeviceType6SPlus;
    if ([platform isEqualToString:@"iPhone8,4"]) return XFSystemDeviceTypeSE;
    if ([platform isEqualToString:@"iPhone9,1"]) return XFSystemDeviceType7;
    if ([platform isEqualToString:@"iPhone9,2"]) return XFSystemDeviceType7Plus;
    if ([platform isEqualToString:@"iPhone10,1"]) return XFSystemDeviceType8;
    if ([platform isEqualToString:@"iPhone10,2"]) return XFSystemDeviceType8Plus;
    if ([platform isEqualToString:@"iPhone10,4"]) return XFSystemDeviceTypeX;
    if ([platform isEqualToString:@"i386"])return XFSystemDeviceTypeSimulator;
    if ([platform isEqualToString:@"x86_64"]) {
        CGSize size = [UIScreen mainScreen].bounds.size;
        if(size.width == 375 && size.height == 812){
            return XFSystemDeviceTypeX;
        }
        return XFSystemDeviceTypeSimulator;
    }
    
    return XFSystemDeviceType4S;
}

+ (void)openSetting{
    
    NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    
    if([[UIApplication sharedApplication] canOpenURL:url]) {
        
        NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];
        [[UIApplication sharedApplication] openURL:url];
    }
}

@end
